package edu.nf.db.util.convertor;

import edu.nf.db.util.TypeConvertor;

import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author zhu
 * @date 2024-05-09
 */
public class LocalTimeConvertor implements TypeConvertor {

    @Override
    public Object convert(Class<?> fieldType, Object value) {
        return switch (value){
            case LocalTime localTime -> localTime;
            case Time time -> time.toLocalTime();
            case LocalDateTime localDateTime -> localDateTime.toLocalTime();
            case Timestamp timestamp -> timestamp.toLocalDateTime().toLocalTime();
            default -> null;
        };
    }

    @Override
    public boolean supports(Class<?> type) {
        return type.equals(LocalTime.class);
    }
}
